/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.suggest;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.suggest.Suggest;

/**
 * @author Administrator (email:granzy@sohu.com)
 * @since 2013-02-25
 */
@Service("suggestService")
public class SuggestServiceImpl implements SuggestService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of Suggest
     ****************************************/
    public void insert(Suggest suggest) throws Exception {
        suggest.setBoxid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(suggest);
    }

    /****************************************
     * Update a instace of Suggest
     ****************************************/
    public void update(Suggest suggest) throws Exception {
        iDataSet4iBatis.update(suggest);
    }

    /****************************************
     * Delete a instace of Suggest
     ****************************************/
    public void delete(Suggest suggest) throws Exception {
        iDataSet4iBatis.delete(suggest);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(Suggest suggest) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(Suggest suggest) throws Exception {
        String statementId = suggest.getStatmentId();
        String mainId = suggest.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> suggestList = new ArrayList<BaseModel>();
        for (String id : ids) {
            Suggest model = new Suggest();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            suggestList.add(model);
        }
        iDataSet4iBatis.batchDelete(suggestList);
    }

    /****************************************
     * Query instaces of Suggest
     ****************************************/
    public List<BaseModel> queryAsList(Suggest suggest) throws Exception {
        String queryListStatement = "";
        if (suggest.isPaging()) {
            queryListStatement = suggest.getStatmentId();
            suggest.setStatmentId("Suggest.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(suggest);
            suggest.setTotalCount(baseModel.getTotalCount());
            suggest.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(suggest);
    }

    /****************************************
     * Query a instaces of Suggest
     ****************************************/
    public BaseModel queryAsObject(Suggest suggest) throws Exception {
        return iDataSet4iBatis.queryAsObject(suggest);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
